package com.javaweb.demo.servlet;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.javaweb.demo.dao.UserDao;
import com.javaweb.demo.dao.UserDaolmpl;
import com.javaweb.demo.entity.Poster;
import com.mysql.cj.xdevapi.JsonArray;
import com.alibaba.fastjson.JSON;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class GetPosterServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        UserDao ud = new UserDaolmpl();
        List<Poster> posterall = ud.getposter();
        Iterator iter = posterall.iterator();
        List<String> stringall = new ArrayList<>();

        while (iter.hasNext()){
            String s = ((Poster)iter.next()).getStr();
            System.out.println(s);
            stringall.add(s);
        }
        String username = request.getParameter("username");

        if (username.equals("daikunqi")){
            System.out.println(username);
            request.setAttribute("PosterAll", posterall);
            request.setAttribute("username", username);
            request.getRequestDispatcher("/PosterListM.jsp").forward(request, response);
        }
        else{
            System.out.println(username);
            request.setAttribute("PosterAll", posterall);
            request.setAttribute("username", username);
            request.getRequestDispatcher("/PosterList.jsp").forward(request, response);
        }

    }

}
